'use strict'

define(['jquery', 'bootstrap', 'shiftform'], function($) {
  
  return {
    
    init: function() {
      this.initPage();
      this.submitForm();
    },
    
    initPage: function() {
      
      $(document).on('click', '#select-all', function(e) {
        
        var checked = $('#select-all').is(':checked');
        $('input[name="shipmentFinanceId"]').prop('checked', checked);
        
      });
      
    },
    
    submitForm: function() {
      
      $('form').shiftform({
        beforeSubmit: function() {
          
          var submit = false;
          $('input[name="shipmentFinanceId"]').each(function(){
            if($(this).is(':checked')) {
              submit = true;
              return false;
            }
          });
          
          if (submit === false) {
            $('div.invalid-message').show();
          }
          
          return submit;
          
        }
      });
      
    }
    
  }
})